<template>
	<view>
		<view class="wx" v-if="isShow">
			<image src="/static/img/wx.png" class="wx-image" mode="aspectFit"></image>
		</view>
		<div class="login-wrapper" style="background-color: white; height: 100vh">
			<div class="shading">
				<image src="/static/images/tz_logo.png" />
			</div>
			<div class="app">数字通证</div>
			<div class="whiteBg">
				<canvas canvas-id="qrcode" style="width: 130px; height: 130px"></canvas>
			</div>
			<text class="txt">扫码获取</text>
			<div class="logon" @click="down('android')">下载安装</div>
		</div>
		<view></view>
	</view>
</template>
<script>
	import uQRCode from "@/js_sdk/Sansnn-uQRCode/uqrcode.js";
	export default {
		data() {
			return {
				weixin: false, //是否为微信内浏览器打开
				isShow: false,
				downloadUrl:"https://img.lbtai.com/file/app/tz/SZTZ_V2.apk"
			};
		},
		onload() {
	this.isWX()
		},
		mounted() {
			this.qrFun()
		},
		 methods: {
		 qrFun(text = 'https://img.lbtai.com/file/app/tz/SZTZ_V2.apk.') {
		 				uQRCode.make({
		 					canvasId: "qrcode",
		 					componentInstance: this,
		 					text, //这里的text需要生成的二维码地址
		 					size: 130, //和上面保持一致即可默认像素
		 					margin: 0,
		 					backgroundColor: "#ffffff",
		 					foregroundColor: "#000000",
		 					fileType: "jpg",
		 					errorCorrectLevel: uQRCode.errorCorrectLevel,
		 					success: (res) => {},
		 				});
		 			},
		  
		 			isWX() {
		 				let ua = navigator.userAgent.toLowerCase();
		 				if (ua.match(/MicroMessenger/i) == "micromessenger") {
		 					this.weixin = true
		 				} else {
		 					this.weixin = false
		 				}
		 			},
		 
		 			down(type) {	
						console.log('XXXXXXXXXXXX')
						this.download(this.downloadUrl)
		 // 				if (this.weixin) {
		 // 					uni.showModal({
		 // 						content: '请点击右上角按钮\n选择在浏览器打开',
		 // 						showCancel: false,
		 
		 // 					});
		 
		 // 					this.isShow = true;
		 // 				} else {
		 // 					if (type == 'android') {
		 
		 // 						// #ifdef H5
		 // 						// window.location.href = this.downloadUrl;
		 // 						// #endif
		 
		 // 						// #ifdef MP-WEIXIN
			// 				console.log('AAAA1111111111111')
		 // 						this.download(this.downloadUrl)
		 
		 // 						// #endif
		 
		 // 					} else {
		 // 						// window.open(this.iosHref);
		 // 					}
		 // 				}
		 
		 			},
		 			download(openUrl) {
						console.log('AAAA222222222222222')
		 				uni.showLoading({
		 					title: '正在下载...',
		 					mask: false
		 				});
		 				uni.downloadFile({
		 					url: openUrl,
		 					success: function(res) {
		 						uni.hideLoading();
		 						console.log(res);
		 						var filePath = res.tempFilePath;
		 
		 						uni.openDocument({
		 							filePath: filePath,
		 							showMenu: true,
		 							success: function(res) {}
		 						});
		 					}
		 				});
		 			},
		 		},
	};
</script>

<style lang="scss" scoped>
	page {
		background: #fff;
	}
	.wx {
			position: fixed;
			left: 0;
			top: 0;
			background-color: rgba(0, 0, 0, .7);
			width: 100vw;
			height: 100vh;
			z-index: 99;

		}

	.login-wrapper {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 30rpx;

		.shading {
			display: flex;
			align-items: start;
			justify-content: center;
			width: 100%;
			margin-top: 175rpx;

			image {
				width: 200rpx;
				height: 200rpx;
			}
		}

		.app {
			color: #4389f1;
			font-weight: bold;
			padding: 25rpx;
			border-bottom: 3px solid #4389f1;
			margin: 0 0 70rpx 0;
		}

		.whiteBg {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 300rpx;
			width: 300rpx;
			border-radius: 24rpx;
			border: 1px solid rgb(19, 157, 19);
		}

		.txt {
			color: #4389f1;
			font-weight: bold;
			margin: 20rpx 0 60rpx 0;
		}

		.logon {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: 86rpx;
			background-color: $theme-color;
			border-radius: 120rpx;
			color: #ffffff;
			font-size: 30rpx;
		}
	}
</style>